package push

import (
	"fmt"
	utils "hft/Http/Utils"
	"hft/tools/weixin/model"
	"hft/tools/weixin/push/push_modules"

	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

// 接收微信推送
type Push struct{}

// 校验
func (*Push) Valid(c *gin.Context) {
	var data model.Check
	c.ShouldBindQuery(&data)
	// 进入校验
	fmt.Println("校验")
	str, err := push_modules.WeiXinCheck.CheckToken(&data)
	if err != nil {
		fmt.Println("发生错误", err)
		utils.FailWithMessage(err.Error(), c)
		return
	}
	fmt.Println("结果", str)
	c.String(200, str)
}

// 总接口
func (*Push) TotalInterface(c *gin.Context) {
	fmt.Println("推送")
	// 推送
	var pushBody model.ReceiveEvent
	c.ShouldBindBodyWith(&pushBody, binding.XML)
	if pushBody.MsgType == "event" {
		// 事件推送
		fmt.Println("事件推送")
		push_modules.EventPushWx.TotalPusher(c)
	} else {
		// 普通消息
		fmt.Println("普通消息")
	}

}

var PushWx = new(Push)
